app.controller('HomeCtrl', function($scope, $http, musicService, $ionicSideMenuDelegate) {
    $http.get('/music/discover').success(function(result) {
        $scope.discover = result;
    });
    $scope.toggleLeft = function() {
        $ionicSideMenuDelegate.toggleLeft();
    };
});

app.controller('PlayerCtrl', function($scope, $routeParams, musicService, $sce) {
    $scope.songUrl = '';
    $scope.src = $sce.trustAsResourceUrl("http://music.163.com/outchain/player?type=2&id=" + $routeParams.id + "&auto=1&height=66");
    musicService.detail($routeParams.id).success(function(res) {
        $scope.song = JSON.parse(res.text).songs[0];
    });
});

app.controller('SearchCtrl', function($scope, musicService, SearchType, $ionicTabsDelegate) {
    $scope.s = 'hello';
    $scope.Single = [];
    $scope.Singer = [];
    $scope.Special = [];
    $scope.Sheet = [];
    $scope.Dj = [];
    $scope.Mv = [];

    var itemArray =
        [
            'Single', //单曲
            'Singer', // 歌手
            'Special', //专辑
            'Sheet', //歌单
            'Dj', //主播电台
            'Mv', // mv
            'Lyc', //歌词
            'User' //用户
        ];
    var types = [SearchType.singer];
    var cur_index = 0;

    $scope.onSearch = function() {
        musicService.search($scope.s, SearchType[$scope.type]).success(function(resp) {
            $scope[$scope.type] = resp.result;
        });
    };

    $scope.onRefresh = function() {

    };

    $scope.type = SearchType.Single;
    
    $scope.onTabSelected = function() {
        var index = $ionicTabsDelegate.selectedIndex();
        console.log(itemArray[index], SearchType[itemArray[index]]);
        $scope.type = itemArray[index];
        $scope.onSearch();
    };
});

app.controller('PlaylistCtrl', function($scope, $routeParams, $sce) {
    var h = angular.element(window).height();
    $scope.src = $sce.trustAsResourceUrl("http://music.163.com/outchain/player?type=0&id=" + $routeParams.id + "&auto=1&height=" + h);
});

app.controller('AlbumCtrl', function($scope, $routeParams, $sce) {
    var h = angular.element(window).height();
    $scope.src = $sce.trustAsResourceUrl("http://music.163.com/outchain/player?type=1&id=" + $routeParams.id + "&auto=1&height=" + h);
});

//歌手页
app.controller('ArtistCtrl', function($scope, $routeParams, $sce) {

});